<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #space invaders - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23space+invaders</link>
      <pubDate>Sun, 08 Aug 2021 20:19:48 +0000</pubDate>
         <description>Tagged with #space invaders - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23space+invaders/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>lessen moving code</title>
      <link>https://forum.processing.org/two/discussion/27929/lessen-moving-code</link>
      <pubDate>Mon, 07 May 2018 04:34:38 +0000</pubDate>
      <dc:creator>ctrembla</dc:creator>
      <guid isPermaLink="false">27929@/two/discussions</guid>
      <description><![CDATA[<p>OK, I'm making a tower defense/ space invaders game and an enemy moves the same way a bunch of times in a row, but when I tried dropping it into a loop the enemy zoomed off the screen. So now I got a bunch of lines of code making the enemy do like a staircase moving. I think there is a way to make it less code, but idk. Here the movement code:</p>

<p><code>int x,y,t,sp;
  int spd = 1;
if (t == 0){
      sp = y;
      t = 1;
    }
    if (t == 1){
      y -= spd;
      if (y &lt;= sp-100){
        t = 2;
        sp = x;
      }
    }
      if (t == 2){
      x -= spd;
      if (x &lt; sp-290){
         t = 3;
         sp = y;
      }
    }// t == 1
    if (t == 3){
      y -= spd;
      if (y &lt;= sp-80){
        t = 4;
        sp = x;
      }
    }
      if (t == 4){
      x += spd;
      if (x &gt; sp+50){
         t = 5;
         sp = y;
      }
    }// t == 1
    if (t == 5){
      y -= spd;
      if (y &lt;= sp-80){
        t = 6;
        sp = x;
      }
    }
    if (t == 6){
      x += spd;
      if (x &gt; sp+50){
         t = 7;
         sp = y;
      }
    }// t == 1
    if (t == 7){
      y -= spd;
      if (y &lt;= sp-80){
        t = 8;
        sp = x;
      }
    }
    if (t == 8){
      x += spd;
      if (x &gt; sp+50){
         t = 9;
         sp = y;
      }
    }// t == 1
    if (t == 9){
      y -= spd;
      if (y &lt;= sp-80){
        t = 10;
        sp = x;
      }
    }
    if (t == 10){
      x += spd;
      if (x &gt; sp+50){
         t = 11;
         sp = y;
      }
    }// t == 1
    if (t == 11){
      y -= spd;
      if (y &lt;= sp-50){
        t = 12;
        sp = x;
      }
    }
    if (t == 12){
      x += spd;
      if (x &gt; sp+70){
         t = 13;
         sp = y;
      }
    }// t == 1
    if (t == 13){
      y += spd;
      if (y &gt;= sp+350){
        t = 14;
        sp = x;
      }
    }
    if (t == 14){
      x += spd;
      if (x &gt; sp+85){
         t = 15;
         sp = y;
      }
    }// t == 1</code></p>

<p>can anyone help me make this code shorter.</p>
]]></description>
   </item>
   <item>
      <title>Trying to create space invaders kind of game.</title>
      <link>https://forum.processing.org/two/discussion/26717/trying-to-create-space-invaders-kind-of-game</link>
      <pubDate>Thu, 08 Mar 2018 17:08:26 +0000</pubDate>
      <dc:creator>LAT</dc:creator>
      <guid isPermaLink="false">26717@/two/discussions</guid>
      <description><![CDATA[<p>Trying to make one from scratch with limited knowledge on coding.  I have been able to get it to move left to right, but I can't seem to get the bullets to stop moving along with the turret or to disappear once it hits the top of the canvas.</p>

<pre><code>float gunX;
float bulletY;
float SPEED = 2.0;
float STALL = 0.0;
int N=0;
final int BLACK = #000000;
final int WHITE = #FFFFFF;
final float gunBodySize = 50;
final float barrelParameterOne=25;
final float barrelParameterTwo=75;
final float bulletDIAM = 5;
final float SPACING = 20;
boolean hitLeftEdge, hitRightEdge,hitTop;
void setup(){
  size(500,500);
  gunX=width/2-barrelParameterOne;
}
void draw(){
  background(150);
  moveBullet();
  drawBullet();
  moveGun();
  drawGun();
}
void moveGun(){
  hitLeftEdge();
  hitRightEdge();
  if (key == CODED) {
    if (hitLeftEdge){
    gunX=0;
    }
    else if (keyPressed &amp;&amp; keyCode == LEFT) {
      gunX+=-SPEED;
    }
    if (hitRightEdge){
      gunX=width-gunBodySize;
    }
    else if (keyPressed &amp;&amp; keyCode == RIGHT) {
      gunX+=SPEED;
    } 
  }
}
void drawGun(){
  fill(WHITE);
  rect(gunX,height, gunBodySize,-gunBodySize);
  triangle(gunX,height-gunBodySize,gunX+barrelParameterOne,height-barrelParameterTwo,gunX+gunBodySize,height-gunBodySize);
}
void hitLeftEdge(){
  if (gunX&lt;0){
    hitLeftEdge =  true;
  }
  else {
    hitLeftEdge = false;
  }
}
void hitRightEdge(){
  if (gunX&gt;width-gunBodySize){
    hitRightEdge = true;
  }
  else {
    hitRightEdge = false;
  }
}
void drawBullet(){
  fill(BLACK);
  if (mousePressed){
    int i = 1;
    while (i&lt;=5){
      bulletY=height-(gunBodySize+SPEED*N)+SPACING*i;
      ellipse(gunX+barrelParameterOne,bulletY,bulletDIAM,bulletDIAM);
      i++;
    }
  }  
}
void moveBullet(){
  checkBullet();
  if(mousePressed &amp;&amp; !hitTop){
    N++;
  }
  else if(mousePressed &amp;&amp; hitTop){
    N=0;
  }
}
void checkBullet(){
  if (bulletY&lt;=0){
    hitTop = true;
  }
  else {
    hitTop = false;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Problem to draw multiple rectangles with loop.</title>
      <link>https://forum.processing.org/two/discussion/25829/problem-to-draw-multiple-rectangles-with-loop</link>
      <pubDate>Fri, 05 Jan 2018 09:27:16 +0000</pubDate>
      <dc:creator>Tristou</dc:creator>
      <guid isPermaLink="false">25829@/two/discussions</guid>
      <description><![CDATA[<p>Hello, i have some trouble making my code work, let me explain :</p>

<p>First we have to draw rectangles everytime there is a 1 on this array :</p>

<pre><code>  int[][] alienSprite = {
    {1, 0, 1, 1, 1, 0, 1}, 
    {0, 1, 0, 1, 0, 1, 0},
    {1, 1, 1, 1, 1, 1, 1},
    {0, 1, 0, 1, 0, 1, 0},
    {1, 0, 0, 0, 0, 0, 1}
  };
</code></pre>

<p>The next thing is to store the position where the invaders will spawn :</p>

<pre><code>  int[] posAlienX = new int[8];

  void setup() { 
    size (800, 600); 
    for (int i = 0; i &lt;posAlienX.length; i++){ 
      posAlienX[i] = x; 
      x = x +100;
    }
  }
</code></pre>

<p>Till now it was very basic stuff, i created 2 arrays, one for the rectangles "pattern", one for the invaders positions...</p>

<pre><code>void alien(){

  int spriteY = 20;
  int n = 0;

  for (int s = 0; s &lt; posAlienX.length; s++){
    int spriteX = posAlienX[s];

    while (n &lt; 7) {

      for (int i = 0; i &lt; alienSprite.length; i++ ){

        if (alienSprite[i][n] == 1){
          fill(125);
          rect(spriteX,spriteY,5,5);
          spriteY = spriteY + 5;
        }
        else if (alienSprite[i][n] == 0){
          spriteY = spriteY + 5; 
        }
      }

      spriteX = spriteX +5;

      spriteY = 20;

      n++;
    }
  } 
}
</code></pre>

<p>when i enter the loop i want SpriteX to be the position of the cell, but it doesn't work.</p>

<p>Unfortunately it draw only one invader (i need 8). I don't understand because i have a loop to change my SpriteX position with the AlienX array. Again i'm new to Java and programming, so thanks for your help and your patience.</p>

<p>it give me this : <img src="" alt="" /></p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/420/KWS4UR6NXDMK.jpg" alt="Sans titre" title="Sans titre" /></p>
]]></description>
   </item>
   <item>
      <title>my enemy won't move correct</title>
      <link>https://forum.processing.org/two/discussion/25591/my-enemy-won-t-move-correct</link>
      <pubDate>Sat, 16 Dec 2017 01:57:43 +0000</pubDate>
      <dc:creator>ctrembla</dc:creator>
      <guid isPermaLink="false">25591@/two/discussions</guid>
      <description><![CDATA[<p>ok, so I thought I'd make my newer version of space invaders like space invaders the regular one &amp; have them all move down together, but they keep just moving indivual.</p>

<p>here the code in enemy I think that all you need idk;</p>

<p><code>class Enemy extends Circle {
  float life = 1;
  float spd = 1;
  float type = 1; // here I give each class a type so I can have several different enemies
  Enemy(float x, float y, float r) {
    super(x, y, r);
  }
  void show() {
    fill(128, 0, 128);
    ellipse(x, y, r*2, r*2);
  }
  void move() {
    x += spd;
    if (x+r &gt; width &amp;&amp; spd &gt; 0) { // here it checks if collide with wall
      for (Enemy e : enemy) { // here I want it to loop through all the enemy
        if (e.type == 1 &amp;&amp; spd &gt; 0) { //any with type = 1 need to move down
          spd *= -1;
          y += 30;
        }
      }
    } else if (x-r &lt; 0 &amp;&amp; spd &lt; 0) { /// I havent done this one yet it for the other side 
      spd *= -1;
      y += 30;
    }
  }
  void grow() {
    for (int i = enemy.size()-1; i &gt;= 0; i--) {
      Enemy e = enemy.get(i);
      if (e.life &lt;= 0) {
        enemy.remove(i);
        control.dead -= 1;
      }
    }
  }
}</code></p>
]]></description>
   </item>
   <item>
      <title>removing a few pixels with hit detection</title>
      <link>https://forum.processing.org/two/discussion/23247/removing-a-few-pixels-with-hit-detection</link>
      <pubDate>Thu, 29 Jun 2017 00:47:57 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">23247@/two/discussions</guid>
      <description><![CDATA[<p>When the bunkers in space invaders get hit, only a few pixels are removed. Do I need to use the pixel array to do that.. or can I do it with the set() function (with loadPixels and updatePixels)... or could I somehow do it with my creation below?</p>

<p>I'm using p5.js.</p>

<p><a href="https://www.openprocessing.org/sketch/429876" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/429876</a></p>
]]></description>
   </item>
   <item>
      <title>P5 copy() and animation question</title>
      <link>https://forum.processing.org/two/discussion/22992/p5-copy-and-animation-question</link>
      <pubDate>Fri, 09 Jun 2017 00:47:36 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">22992@/two/discussions</guid>
      <description><![CDATA[<p>Does anyone know if there is an easy way to make these aliens move faster and be better?
    <a href="https://www.openprocessing.org/sketch/433119" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/433119</a></p>

<p>When the alien is by itself, it moves faster and looks better than in the array. I just change the dx = dx + 5 line.
    <a href="https://www.openprocessing.org/sketch/428281" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/428281</a></p>

<p>when I try to change the speed in lines 43 and 53 in the array sketch, it looks terrible.</p>

<p>Thank you,</p>
]]></description>
   </item>
   <item>
      <title>How to Make the Eye Monsters Disappear?</title>
      <link>https://forum.processing.org/two/discussion/22738/how-to-make-the-eye-monsters-disappear</link>
      <pubDate>Wed, 24 May 2017 12:37:06 +0000</pubDate>
      <dc:creator>Amirrudin_ISM</dc:creator>
      <guid isPermaLink="false">22738@/two/discussions</guid>
      <description><![CDATA[<p>I'm making a simple space invader clone. I got everything down except making the eye monsters disappear after getting hit.
I'm using a for-loop for drawing them.</p>

<p>Here's the code:</p>

<pre><code>   void setup(){
      size(500,500);

    }

    void draw(){
      frameRate(60);
      clear();
      spaceBackground();
      spaceship();
       for(int i=0;i&lt;9;i++){
        for(int j=0; j&lt;1; j++){
          enemies(50*i+50,50*j+50);
      }
     }

      if (mousePressed){
        clicked = 1;
      }

      if (clicked == 1){
        xPos = mouseX;
        bullet();
        bulletSpeed();
        if (yPos &lt;= 0){
         yPos = 375;
         clicked = 0;
        }
      }
    }

    void spaceship(){// draws spaceship
      noStroke();
      fill(255,0,0);
      triangle(mouseX,390,mouseX-30,460,mouseX+30,460);
      fill(255,255,0);
      triangle(mouseX-15,420,mouseX-30,460,mouseX-15,460);
      fill(255,255,0);
      triangle(mouseX+15,420,mouseX+30,460,mouseX+15,460);
      fill(0,0,255);
      ellipse(mouseX,435,20,20);
      fill(255);
      ellipse(mouseX+3,435-5,6,6);
    }

    void spaceBackground(){ //draws starry background
      for(int i=0;i&lt;20;i++){
        for(int j=0;j&lt;20;j++){
          strokeWeight(2);
          stroke(random(255), random(255),random(255));
          point(random(0,width),random(0,height));
        }
      }
    }

    float yPos=375;
    float ySpeed=50;

    void bulletSpeed(){//functions that adds vertical speed to the bullets
     yPos=yPos-ySpeed;
    }



    void bullet(){//draws bullet
      for(int i=5;i&gt;0;i--){
        noStroke();
        fill(i*50,i*50,255);
        ellipse(xPos,yPos,i*5,i*5);
      }
    }

    void enemies(int xPos, int yPos){//draws eye aliens
      stroke(0);
      fill(255);
      strokeWeight(1);
      ellipse(xPos,yPos,40,40);
      fill(255,0,0);
      ellipse(xPos,yPos,20,20);
      strokeWeight(4);
      point(xPos,yPos);
      stroke(255);
      point(xPos+3,yPos-3);
    }
</code></pre>

<p>Sorry about the really bad layout. I'm new to these things.</p>
]]></description>
   </item>
   <item>
      <title>p5.js animate question</title>
      <link>https://forum.processing.org/two/discussion/22626/p5-js-animate-question</link>
      <pubDate>Wed, 17 May 2017 00:34:09 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">22626@/two/discussions</guid>
      <description><![CDATA[<p>In the example I share here, I have an array of aliens. I'm trying to get the aliens to animate as they do in the original game. For every alien you see in the sketch, there is another alien underneath it. Is there anyway I can get the aliens to jump from 1 to 2 and back..... sort of like this: 1, 2, 1, 2, 1, 2 as they move across the screen? or like this: ( <strong>_</strong> ) (^_^) ( <strong>_</strong> ) (^_^) ( <strong>_</strong> )...</p>

<p>I'm a NOOB so I barely understand anything.</p>

<p><a href="https://openprocessing.org/sketch/428354" target="_blank" rel="nofollow">https://openprocessing.org/sketch/428354</a></p>
]]></description>
   </item>
   <item>
      <title>i am making a space invaders clone for class and i cant get it to work</title>
      <link>https://forum.processing.org/two/discussion/22469/i-am-making-a-space-invaders-clone-for-class-and-i-cant-get-it-to-work</link>
      <pubDate>Mon, 08 May 2017 18:22:42 +0000</pubDate>
      <dc:creator>jozefvelez</dc:creator>
      <guid isPermaLink="false">22469@/two/discussions</guid>
      <description><![CDATA[<p>A certain if statement ws screwing me over but it is gone now because my program currupted</p>
]]></description>
   </item>
   <item>
      <title>stuck again (Invaders)</title>
      <link>https://forum.processing.org/two/discussion/22094/stuck-again-invaders</link>
      <pubDate>Thu, 20 Apr 2017 04:52:08 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">22094@/two/discussions</guid>
      <description><![CDATA[<p>How do I make these aliens into one variable? Once I start shooting them, they become a mess of confusion.</p>

<p>I have no idea what do to.</p>

<p>If you answer, please talk to me like you'd talk to a five year old... Thanks.</p>

<p><a href="https://openprocessing.org/sketch/421935" target="_blank" rel="nofollow">https://openprocessing.org/sketch/421935</a></p>
]]></description>
   </item>
   <item>
      <title>Sprite</title>
      <link>https://forum.processing.org/two/discussion/22146/sprite</link>
      <pubDate>Sun, 23 Apr 2017 00:07:10 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">22146@/two/discussions</guid>
      <description><![CDATA[<p>In p5 not processing, does anybody know how to turn this sprite thing into full graphics? I'm a total noob.</p>

<p><a href="https://github.com/maxwihlborg/youtube-tutorials/blob/master/space-invaders/res/invaders.png" target="_blank" rel="nofollow">https://github.com/maxwihlborg/youtube-tutorials/blob/master/space-invaders/res/invaders.png</a></p>
]]></description>
   </item>
   <item>
      <title>How to make the invader can shoot by theirself?</title>
      <link>https://forum.processing.org/two/discussion/22113/how-to-make-the-invader-can-shoot-by-theirself</link>
      <pubDate>Thu, 20 Apr 2017 20:41:56 +0000</pubDate>
      <dc:creator>LeegeeRicky</dc:creator>
      <guid isPermaLink="false">22113@/two/discussions</guid>
      <description><![CDATA[<p>Hi there, I'm making a game where something comes across the screen, from one side to the other. What I'd like to do is that the invader can shoot the bullet itself at a random moment by using 1D array not the arraylist, and I'm really stuck with it... Here is what i got so far:</p>

<pre><code>    //Main class
    int AlienRow = 4;
    int AlienCol = 8;
    int AfirstNullBullet = 0;
    Alien[][] alien = new Alien[AlienCol][AlienRow];
    BulletAlien[] bulletAlien = new BulletAlien[5];

    void setup()
    {
      size(700, 600);
      gameStart();
      setAlien();
    }

    void draw()
    {
      background(255);
    }

    void setAlien()
    {
      /* Set up the position of the image and how many rows and cols */
      for (int i = 0; i &lt; AlienCol; i++) 
      {
        for (int j = 0; j &lt; AlienRow; j++) 
        {
          alien[i][j] = new Alien(30 * (2*(i+1)), 30 * (1*(j+1)));
        }
      }//end for loop
    }

    void displayBullets() 
    {
      for (int a = 0; a &lt; bulletAlien.length; a++)
      {
        if (bulletAlien[a] != null)
        {
          bulletAlien[a].Adisplay();
          bulletAlien[a].Amove();

          if (bulletAlien[a].ay &lt; height || bulletAlien[a].ay &gt; 0)
          {
            bulletAlien[a] = null;
          } else
          {
            AfirstNullBullet = a;
        }
      }
    }

    //Alien class
    class Alien
    {
      float x, y;
      float ximg = 0;
      float speed = 2;

      Boolean moveLeft = false;

      Alien(float x, float y)
      {
        this.x = x;
        this.y = y;
      }

      void display()
      {
        eclipse(x, y, 40, 40);
      }

      void move() 
      { 
        if (!moveLeft)
        {
          x += speed;
        }
        if (moveLeft)
        {
          x -= speed;
        }
        if (x &lt;= 0)
        {
          moveLeft = false;
          y += 90;
        }
        if (x &gt;= width - 30)
        {
          moveLeft = true;
          y += 90;
        }
        if (y &gt;= 550)//When the alien go out of the button the game wiil end
        {
          gameEnd = true;
        }
      }

      void update() 
      {
        display();
        move();
      }

      void Alienshoot() 
      {
        if (int (random(100)) &gt; 0) 
        {
          bulletAlien[AfirstNullBullet] = new BulletAlien(x, y, 20);
        }
      }
    }

    //Bullet class
    class BulletAlien 
    {
      float ax, ay;
      float aspeed;

      BulletAlien(float ax, float ay, float aspeed) 
      {
        this.ax = ax;
        this.ay = ay;
        this.aspeed = aspeed;
      }

      void Adisplay()
      {
        fill(255, 255, 255);
        rect(ax, ay, 4, 15);
      }

      void Amove()
      {
        ay -= aspeed;
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Move Alien Invaders from Side to Side</title>
      <link>https://forum.processing.org/two/discussion/21832/move-alien-invaders-from-side-to-side</link>
      <pubDate>Wed, 05 Apr 2017 17:42:16 +0000</pubDate>
      <dc:creator>bsaid97</dc:creator>
      <guid isPermaLink="false">21832@/two/discussions</guid>
      <description><![CDATA[<p>Hello all, I'm trying to make a simple space invaders game. For now, the aliens, which are taxis in this case, are moving along down the y-axis without moving horizontally across the x-axis.</p>

<p>This is code that I've written:</p>

<pre><code>boolean move(){
    if(gameMode==EASY){
      y= y+random(0.15, 0.5);
    }else{
      y=y+random(0.3, 0.5);
    }
    for(Taxi taxi: taxis){
      taxi.x= taxi.x+deltaX;
      if(taxi.x&gt;=600){
        deltaX*= -1;
      }

      if(taxi.x&lt;=0){
        deltaX*= -1;
      }
    }
  return (y&lt;=def1.y);
  }
</code></pre>

<p>Currently, the taxis are moving from side to side as I wanted. However, right now I'm running with 2 rows, 5 columns of aliens, for some reason, the change of direction is only activated at the 4th column, meaning the 5th column disappears off screen. This is only occurring on the right side too, so taxi.x&lt;=0 is fine, it seems. 
The width of the game is 400px as indicated in the setup:</p>

<pre><code>void setup(){
  size(400, 700);
  gameMode=SPLASH;
  reset();
}
</code></pre>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>space invaders game code, please help</title>
      <link>https://forum.processing.org/two/discussion/21287/space-invaders-game-code-please-help</link>
      <pubDate>Thu, 09 Mar 2017 16:36:52 +0000</pubDate>
      <dc:creator>ajricky</dc:creator>
      <guid isPermaLink="false">21287@/two/discussions</guid>
      <description><![CDATA[<p>I am currently making a space invaders game, but now I'm struggling with how to make the Alien shot. I try to use floor(random()); method, But it doesn't work. Here is my main code below:</p>

<pre><code>PImage background;
int by = 0;
Shooter Shooter1;

int AlienRow = 3;
int AlienCol = 8;
int firstNullBullet = 0;
Alien[][] alien = new Alien[AlienCol][AlienRow];
Bullet[] bullet = new Bullet[2];

Boolean keyLeftPress = false, keyRightPress = false, gameEnd = false, gameWin = false;

int score = 0;

void setup()
{
  size(700, 600);
  gameStart();
  setAlien();
  background = loadImage("Space.jpg");
  background.resize(700, 600);
}

void draw()
{
  background(255);
  image(background, 0, by);

  Score();
  gameWin();
  gameWinEnd();
}

void gameStart()
{
  Shooter1 = new Shooter();
}

void setAlien()
{
  /** Set up the position of the image and how many rows and cols */
  for (int i = 0; i &lt; AlienCol; i++) 
  {
    for (int j = 0; j &lt; AlienRow; j++) 
    {
      alien[i][j] = new Alien(30 * (2*(i+1)), 30 * (1*(j+1)));
    }
  }//end for loop
}

void displayAlienCheckHit()
{
  /** display the alien from the procedure of Alien class and check the bullet hitting the
   alien and go disappeared */
  for (int i = 0; i &lt; AlienCol; i++) 
  {
    for (int j = 0; j &lt; AlienRow; j++) 
    {
      if (alien[i][j] != null) 
      {
        alien[i][j].update();//display the alien and moving
        for (int o = 0; o &lt; bullet.length; o++)
        {
          if (bullet[o] != null &amp;&amp; alien[i][j] != null)
          {
            Bullet b = bullet[o];
            float dist = dist(b.x, b.y, alien[i][j].x, alien[i][j].y); //set the check point between the alien and bullet
            if (dist &lt; 30 &amp;&amp; b.speed &lt; 0)//if the check point is small than 30 the alien and the bullet will go disappeared
            {
              alien[i][j] = null;
              bullet[o] = null;
              score++;//Count the hitting
            }
          }
        }
      }
    }
  }//end for loop
}

void moveShooter1() 
{
  if (keyLeftPress  &amp;&amp; Shooter1.x &gt; 10) 
  {
    Shooter1.x -=10;
  }
  if (keyRightPress &amp;&amp; Shooter1.x &lt; width - 30) 
  {
    Shooter1.x +=10;
  }
}

void displayBullets() 
{
  /** If the bullet not null, do the procedure from the Bullets class. 
   If is less than 0, the bullet going to be null and disappear */
  for (int i = 0; i &lt; bullet.length; i++) 
  {
    if (bullet[i] != null) 
    {
      bullet[i].display();
      bullet[i].move();

      if (bullet[i].y &gt; height || bullet[i].y &lt; 0)//if the bullet out of the top of the screen and bullet go disappeared
      {
        bullet[i] = null;
      }
    } else //else the bullet keep going
    {
      firstNullBullet = i;
    }
  }
}

void keyPressed()
{
  if (keyCode == LEFT &amp;&amp; !gameEnd)
  {
    keyLeftPress = true;
  } 
  if (keyCode == RIGHT &amp;&amp; !gameEnd)
  {
    keyRightPress = true;
  } 
  if (key == ' ' &amp;&amp; !gameEnd)
  {
    Shooter1.shoot();
  }
  if (key == 'y' &amp;&amp; gameEnd)
  {
    gameEnd = false;
    setup();
  }
  if (key == 'e' &amp;&amp; gameWin)
  {
    gameWin = true;
    exit();
  }
}

void keyReleased() 
{
  if (keyCode == LEFT) 
  {
    keyLeftPress = false;
  } else 
  {
    if (keyCode == RIGHT) 
    {
      keyRightPress = false;
    }
  }
}

// and here is my code for the Alien:

    PImage Alien;

    class Alien
    {
      float x, y;
      float ximg = 0;
      int speed = 2;

      Boolean moveLeft = false;

      Alien(float x, float y)
      {
        this.x = x;
        this.y = y;
        Alien = loadImage("invaderv3.png");
        Alien.resize(40, 40);
      }

      void display()
      {
        image(Alien, x, y);
      }

      void move() 
      { 
        if (!moveLeft)
        {
          x += speed;
        }
        if (moveLeft)
        {
          x -= speed;
        }
        if (x &lt;= 0)
        {
          moveLeft = false;
          y += 90;
        }
        if (x &gt;= width - 30)
        {
          moveLeft = true;
          y += 90;
        }
        if (y &gt;= 550)//When the alien go out of the button the game wiil end
        {
          gameEnd = true;
        }
      }

      void update() 
      {
        display();
        move();
      }

      /**void AlienShoot()
       {
       Bullet b = new Bullet(this.x, this.y, 5);

       }*/
    }
</code></pre>

<p>Class for my bullet:</p>

<pre><code>class Bullet 
{
  float x, y;
  float speed;

  Bullet(float x, float y, float speed) 
  {
    this.x = x;
    this.y = y;
    this.speed = speed;
  }

  void display()
  {
    fill(random(255), random(255), random(255));
    rect(x, y, 2, 15);
  }

  void move()
  {
    y += speed;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Graphics question</title>
      <link>https://forum.processing.org/two/discussion/21382/graphics-question</link>
      <pubDate>Mon, 13 Mar 2017 19:40:40 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">21382@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm new to this. I'm trying to bend my mind around vector and raster (bitmap) graphics. Which one does P5.js use? Is there a good beginner book on the subject? Which graphic type would be best for an evolving game where I start with quality graphics space invaders hoping to evolve to a flying ship and evolve further and further along to who knows where, but to start I need aliens, ship, bunkers, missiles... also of course I need to move them all around... Is there a good book, one perhaps that includes P5, that you could recommend? I hope that was clear. thanks so much..</p>
]]></description>
   </item>
   <item>
      <title>TypeError: undefined is not an object (evaluating 'bunker.x')</title>
      <link>https://forum.processing.org/two/discussion/21362/typeerror-undefined-is-not-an-object-evaluating-bunker-x</link>
      <pubDate>Mon, 13 Mar 2017 01:03:23 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">21362@/two/discussions</guid>
      <description><![CDATA[<p>Hello, does anyone know how I can get the computer to understand my bunker x, y variables? I would rather use other.x, other.y. other.r than bunker.x, bunker.y, and bunker.r but either way I'm lost.</p>

<pre><code>var bunkers = [];
var b1;

function setup() {
      createCanvas(window.innerWidth, window.innerHeight);
      b1 = new Bubble(250, 200);
        for (var i = 0; i &lt; 4; i++){
           bunkers[i] = new Bunker(i*294 + 247, height-140);
   }
}

function draw() {
      background(0);

      for (var i = 0; i &lt; 4; i++){
            bunkers[i].show();
  }
      b1.update();
      b1.display();

      if (b1.intersects(bunkers[i])){
            bunkers[i].changeColor();
    }
}
function Bubble(x, y) {
      this.x = x;
      this.y = y;
      this.r = 48;
      this.col = color(255);
      this.changeColor = function() {
            this.col = color(random(255), random(255), random(255))

    }
      this.display = function() {
            stroke(255);
            fill(this.col);
            ellipse(this.x, this.y, this.r * 2, this.r * 2);

    }

       this.intersects = function(bunker) {
             var d = dist(this.x, this.y, bunker.x, bunker.y);
       if (d &lt; this.r + bunker.r) {
                  return true;
        } else {
                  return false;

        }
 }

       this.update = function() {
            this.x = this.x + random(-5, 5);
            this.y = this.y + random(-5, 5);

    }

}

function Bunker(x, y) {
       this.x = x;
      this.y = y;
      this.r = 60;
       this.show = function(){
          push();
          translate(this.x-257, this.y-68);
          noStroke();
          fill(0, 100, 0);
          beginShape();
          vertex(200, 50);
          vertex(208, 50);
          vertex(208, 42);
          vertex(216, 42);
          vertex(216, 34);
          vertex(224, 34);
          vertex(224, 26);
          vertex(290, 26);
          vertex(290, 34);
          vertex(298, 34);
          vertex(298, 42);
          vertex(306, 42);
          vertex(306, 50);
          vertex(314, 50);
          vertex(314, 110);
          vertex(290, 110);
          vertex(290, 102);
          vertex(282, 102);
          vertex(282, 94);
          vertex(274, 94);
          vertex(274, 86);
          vertex(240, 86);
          vertex(240, 94);
          vertex(232, 94);
          vertex(232, 102);
          vertex(224, 102);
          vertex(224, 110);
          vertex(200, 110);
          endShape(CLOSE);
          pop();
   } 
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>invaders rows moving down the y axis</title>
      <link>https://forum.processing.org/two/discussion/20907/invaders-rows-moving-down-the-y-axis</link>
      <pubDate>Mon, 20 Feb 2017 22:33:41 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">20907@/two/discussions</guid>
      <description><![CDATA[<p>I'm a noob. How do you know this stuff?</p>

<p>If my code is messy, I had to indent it here in the forum to get it onto the forum.</p>

<p>How do I get the Invaders to move down the y-axis?</p>

<p>Now, I'm a noob, so if you say something like: "just inherit a class" or something... that won't help me. Like, I won't know what you mean.  Since I'm a noob.</p>

<p>Also when I run my python server, I can't get my blue files to show up in the browser... so when in your browser you have:
localhost:8000      and under that you have blue files like:</p>

<pre><code>sketch.js
index.html
main.js
et cetera
</code></pre>

<p>I don't have those 4 files. Which ones do I have? None. I have none. It worked before. I'm probably missing a dot or it is some path thing.</p>

<p>Like when you run your python server, have you ever not had the blue files in the browser? If so, what did you do? Perhaps something like localhost:8000 (right, we got that and then perhaps) //some code here(?)</p>

<p>Here is the code below where I don't know how to make the invaders go down the y-axis when it hits the sides.</p>

<p>Also, does anyone know why I can only use one javascript file in my P5 index.html code? If I use two javascript files, only one will work. I use vim and I tried it in text wrangler. Of course neither worked. Has anyone had this problem?</p>

<pre><code>var invaders = [];

   function setup() {
     createCanvas(windowWidth, windowHeight);
     colorMode(HSB);
     for (var i = 0; i &lt; 10; i++) {
     invaders[i] = new Invader(i * 60, 50);
     }
   }

  function draw() {
     background(60, 100, 100);

   var edge = false;
   for (var i = 0; i &lt; invaders.length; i++) {
   invaders[i].display();
    invaders[i].move();
    if (invaders[i].x &gt; width || invaders[i].x &lt; 0) {
    edge = true;
    }
  }

  if (edge) {
    for (var i = 0; i &lt; invaders.length; i++) {
      invaders[i].shiftDown();
    }
  }
}

function Invader(x, y) {
  this.x = x;
  this.y = y;
  this.xdir = 3;
  this.diameter = 50;
  this.display = function() {
    strokeWeight(2);
    stroke(0, 100, 100);
    noFill();
    ellipse(this.x, this.y, this.diameter, this.diameter);
    ellipse(this.x, this.y * 2.2, this.diameter, this.diameter);
    ellipse(this.x, this.y * 3.4, this.diameter, this.diameter);
    ellipse(this.x, this.y * 4.6, this.diameter, this.diameter);
    ellipse(this.x, this.y * 5.8, this.diameter, this.diameter);

  }

  this.shiftDown = function() {
    this.xdir *= -1;
    this.y += this.diameter;
 }

  this.move = function() {
    this.x = (this.x + this.xdir);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>space invader movement question</title>
      <link>https://forum.processing.org/two/discussion/20890/space-invader-movement-question</link>
      <pubDate>Mon, 20 Feb 2017 04:39:04 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">20890@/two/discussions</guid>
      <description><![CDATA[<p>I'm a noob. I can't get the space invaders to move down the y axis. I think I may have made the rows of the invaders badily. How do I get the invaders to move down the y axis?  Also I can't run more than one javascript file in my html doc.</p>

<p>Thanks.</p>

<pre><code>var invaders = [];

   function setup(){
       createCanvas(windowWidth, windowHeight);
       colorMode(HSB);
       for (var i = 0; i &lt; 10; i++){
       invaders[i] = new Invader(i*60, 50);
       }
     }
  function draw(){
      background(60, 100, 100);

      var edge = false;
      for (var i =0; i &lt; invaders.length; i++){
      invaders[i].display();
      invaders[i].move();
      if (invaders[i].x &gt; width || invaders[i].x &lt; 0){
          edge = true;
     }
    }

       if (edge){
       for (var i =0; i &lt; invaders.length; i++){
      invaders[i].shiftDown();
   }
  }
 }
  function Invader(x, y){
     this.x = x;
      this.y = y;
      this.xdir = 3;
      this.diameter = 50;
      this.display = function(){
          strokeWeight(2);
          stroke(0, 100, 100);
          noFill();
          ellipse(this.x, this.y, this.diameter, this.diameter);
          ellipse(this.x, this.y*2.2, this.diameter, this.diameter);
          ellipse(this.x, this.y*3.4, this.diameter, this.diameter);
          ellipse(this.x, this.y*4.6, this.diameter, this.diameter);
          ellipse(this.x, this.y*5.8, this.diameter, this.diameter);

      }

      this.shiftDown = function(){
          this.xdir *= -1;
          //this.y = 1; 
 }

  this.move = function(){
  this.x = (this.x + this.xdir);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Help with Space Invaders - moving Aliens down and across (rectangles)</title>
      <link>https://forum.processing.org/two/discussion/19717/help-with-space-invaders-moving-aliens-down-and-across-rectangles</link>
      <pubDate>Tue, 13 Dec 2016 03:37:26 +0000</pubDate>
      <dc:creator>mesiah67</dc:creator>
      <guid isPermaLink="false">19717@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm new here and having a bit of trouble with some basic Space Invaders code.</p>

<p>Here is my code:</p>

<pre><code>    int x = (200);
    int y = (450);

    int a = 0;
    int b = 54;
    int c = 85;

    int xPos = 25;
    int yPos = 25;
    int xdir = 3; 
    int ydir = 40;

    int counter = 0;

    int[][] enemies = generateEnemies();


    int[][] generateEnemies() {
     int[][] enem = new int[54][2];
     int counter = 0;
     for (int xi = 0; xi &lt; 9; xi++) {
       for (int yi = 0; yi &lt; 6; yi++) {
         enem[counter][0] = xi * 50 + xPos;
         enem[counter][1] = yi * 25 + yPos;
         counter++;
        }
      }
      return enem;
    }

    void setup() {
      size(500, 500);
      frameRate(60);
    }

    void draw() {
      background(0);
      player();
      drawEnemies();
      moveEnemiesRight();

    }

    void player() {
      fill(0, 255, 0);
      rect(x, y, 100, 20);
    }

    void drawEnemies() {

      fill(255, 215, 0);
      for (int i = 0; i &lt; 54; i++) {
        rect(enemies[i][0], enemies[i][1], 40, 20);
      }
    }

    void moveEnemiesRight() {
      xPos += 5;
    }
</code></pre>

<p>This is super messy and lots of crap going on. This is due to me being very inexperienced in the language. My main problem is that I am unable to make the Enemies move down and across the screen. I tried to adjust their position using the xPos variable but could see it wasn't working and can't seem to see a solution.</p>

<p>Any help or guidance is appreciated. Thank you.</p>
]]></description>
   </item>
   <item>
      <title>I made game :)</title>
      <link>https://forum.processing.org/two/discussion/17541/i-made-game</link>
      <pubDate>Fri, 15 Jul 2016 11:12:25 +0000</pubDate>
      <dc:creator>vito_Z80</dc:creator>
      <guid isPermaLink="false">17541@/two/discussions</guid>
      <description><![CDATA[<p>one weeks i made this game, and 4 days for find graphix &amp; music.
worked only win 64.</p>

<p>linux not worked for sound library</p>

<p>Please say me, how i made installer for my game with java at once ?</p>

<p><a rel="nofollow" href="https://youtu.be/P6ODSoaFIYM">Game video</a> 
under video there is a source code</p>
]]></description>
   </item>
   <item>
      <title>Shooting</title>
      <link>https://forum.processing.org/two/discussion/16848/shooting</link>
      <pubDate>Fri, 27 May 2016 13:39:20 +0000</pubDate>
      <dc:creator>martango</dc:creator>
      <guid isPermaLink="false">16848@/two/discussions</guid>
      <description><![CDATA[<p>i'm using images for bullets and my ship has to shoot aliens when i pressed space bar. how  can i make it  as simple as i can ?</p>

<p>i did something like that but this is one time bullet. It has to continuously shoot.</p>

<pre><code>  noCursor();
  background(0);

  image(s1, mouseX,650);
  image(p1, 20, 30);

  if (keyPressed) {
    if (keyPressed == true &amp;&amp; key ==' ') {
      image(n1, mouseX, bo);
    }
  }
  bo = bo -10;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>clicking images and running functions</title>
      <link>https://forum.processing.org/two/discussion/16662/clicking-images-and-running-functions</link>
      <pubDate>Tue, 17 May 2016 11:30:57 +0000</pubDate>
      <dc:creator>martango</dc:creator>
      <guid isPermaLink="false">16662@/two/discussions</guid>
      <description><![CDATA[<p>hello everyone, im doing a space invader like game, but  this one has a selection screen  like street fighter &amp; mortal combat for selecting ships.</p>

<p>i defined the specific coordinates for specific images and wrote the code for this  but  when i clicked  code is running but when i  released im turning back to  select screen.</p>

<p>how can i make this function permanent ?</p>

<p>sorry for grammer btw im'not native !</p>
]]></description>
   </item>
   <item>
      <title>Space Invaders help</title>
      <link>https://forum.processing.org/two/discussion/16630/space-invaders-help</link>
      <pubDate>Mon, 16 May 2016 03:58:10 +0000</pubDate>
      <dc:creator>danielpob</dc:creator>
      <guid isPermaLink="false">16630@/two/discussions</guid>
      <description><![CDATA[<p>Someone could please help me modified enemy ships. I want that enemies shoot, the code is half Spanish and half English</p>

<p><a href="https://www.dropbox.com/s/mbzrfqf1k2mw6hr/Final%20poo.rar?dl=0" target="_blank" rel="nofollow">https://www.dropbox.com/s/mbzrfqf1k2mw6hr/Final poo.rar?dl=0</a></p>
]]></description>
   </item>
   <item>
      <title>Help with space invaders game</title>
      <link>https://forum.processing.org/two/discussion/14897/help-with-space-invaders-game</link>
      <pubDate>Sat, 13 Feb 2016 22:19:48 +0000</pubDate>
      <dc:creator>Jim1597</dc:creator>
      <guid isPermaLink="false">14897@/two/discussions</guid>
      <description><![CDATA[<pre><code>//NOT PROPERLY WORKING ARRAY
int cols= 3; 
int rows=2; 
//int cols_select; 
//int rows_select; 

Alien[][] aliens = new Alien[cols][rows]; 

PImage background;
int y=0;
int bulletX;
int bulletY;
int score=0;
int alienx;
int alieny;

final int NORMAL=0;
final int CRASHED=1;
int gameMode=NORMAL;

//calling the constractors
   //!ALIENS!
   //Alien alien1=new Alien(200,30);
   //Alien alien2=new Alien(400,30);
   //Alien alien3=new Alien(600,30);
   //Alien alien4=new Alien(200,130);
   //Alien alien5=new Alien(400,130);
   //Alien alien6=new Alien(600,130);

   //!DEFENDER!
   Defender defender1;

   //!BULLET!
   bullet  bullet1;

void setup()
{
  bulletX=0;
  bulletY=-100;
  size(1000,800);
  background=loadImage("bg1.jpg");
  image(background,0,0);
  background.resize(width,height);//resize the image to the size of my background
 // bullets=new ArrayList();

    //NOT PROPERLY WORKING ARRAY
    //creating the array
     for (int i=0; i&lt; cols; i++){ 
      for (int j=0; j&lt;rows; j++){ 
        aliens[i][j] = new Alien(alienx,alieny); 
        alienx=alienx+70;
        alieny=alieny+20;
       }
      } 
  bullet1=new bullet(bulletX,bulletY);
  defender1=new Defender(320,450);  

}//end of setup

void draw()
{
  if (gameMode==NORMAL)
  {
    background(255);
    image(background,0,y);
    image(background,0,y+height);
    y=y-10;

    if (y==-background.height)
    {
      y=0;
    }

  //  for (int i=0; i&lt;bullets.size(); i++)
    //{
      //bullet.update();
    //}

    //alien1.update();
    //alien2.update();
    //alien3.update();
    //alien4.update();
    //alien5.update();
    //alien6.update();

    //NOT WORKING PROPERLY ARRAY
   for (int i=0; i&lt; cols; i++){ 
    for(int j=0; j&lt;rows; j++){ 
      aliens[i][j].update();
   }
    }    


   // boolean AlienOnScreen;
   // AlienOnScreen=alien1.update();
    //AlienOnScreen=alien2.update();
    //AlienOnScreen=alien3.update();


    //  if (AlienOnScreen==false)
      //{
        //alien1=new Alien(200,30);
        //alien2=new Alien(400,30);
        //alien3=new Alien(600,30);
      //}

      defender1.render();
      bullet1.update();

      textSize(30);
      fill(255);
      text("SCORE:"+score,30,30);

      if (defender1.crash()||(bullet1.crash())==true)
      {
        //fill(255);
        //text("YOUR SCORE IS:",score,220,420);

        fill(255,0,0);
        textSize(30);
        text("GAME OVER PRESS R TO TRY AGAIN",240,400);
        gameMode=CRASHED;
      }    

       if (defender1.crash()||(bullet1.crash())==true)
      {
        score=score+50;
      }
  }
}

  void keyPressed()
  {
    if (key==CODED)
    {
      if (keyCode==UP &amp;&amp; defender1.y&gt;=400)
      {
        defender1.y=defender1.y-10;
      }
      else if (keyCode==DOWN &amp;&amp; defender1.y&lt;=height-260)
      {
        defender1.y=defender1.y+10;
      }
      else if (keyCode==RIGHT &amp;&amp; defender1.x&lt;width-130)
      {
        defender1.x=defender1.x+20;
      }
      else if (keyCode==LEFT &amp;&amp; defender1.x&gt;15)
      {
       defender1.x=defender1.x-20;
      }
    }
          if (key=='r' &amp;&amp; gameMode==CRASHED)
          {
              gameMode=NORMAL;

             // alien1=new Alien(200,30);
             // alien2=new Alien(400,30);
             // alien3=new Alien(600,30);
              //alien4=new Alien(200,130);
              //alien5=new Alien(400,130);
              //alien6=new Alien(600,130);

              //aliens[i][j].update();    

          bullet1=new bullet(bulletX+1000,bulletY+1000);
          defender1=new Defender(320,450);

         }

    if (key==' ')
    {
      bulletX=defender1.x+75;
      bulletY=defender1.y;

      bullet1=new bullet(bulletX, bulletY);
     // bullet2=new bullet(bulletX, bulletY);

    }  
} 
</code></pre>

<p>Here is my alien class:</p>

<pre><code>class Alien 
{
  int y=100;
  int x=10;
  int v=5;

  Alien (int x ,int y)
  {
    this.x=x;
    this.y=y;
  }

//boolean move()
//{
  //y=y+1;
  //x=x;

  //if (y&gt;=0)
  //{
    //return true;
  //}
  //else 
 // {
   //return false;

  //}
//}//end of the boolean

   void move ()
  {

    x=x+v;  // which direction the alien is moving

    if(x&gt; width - 25)

    { 
      v = -5;
      y = y+30;
    }
    if (x==25)
    {
      v =+5;
      y= y+30;
    }

  }//end of move

void create()
{
    fill(255,255,255);
    ellipse(x,y,45,50);
    fill(255,0,0);
    ellipse(x,y,60,25);
}

void update()
{
  create();
  move();
  //y=y+50;

}
}//end of class
</code></pre>

<p>i want to get 3 columns with 2 rows of aliens in fixed place with a simple moving pattern for some reason tho i cant get them to display properly with are going diagonally and the other problem that i have is when i try to press "r" and restart the game and set the aliens in the same place where they start it wont work they just keep going from where they left</p>

<p>Any help would be appreciated thanks in advance can put all the code if someone wants to check it</p>
]]></description>
   </item>
   </channel>
</rss>